package ru.timofeyco.justfeelbetter.adapters;

import java.util.ArrayList;

import ru.timofeyco.justfeelbetter.R;
import ru.timofeyco.justfeelbetter.model.DrillType;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class SelectTypesAdapter extends ArrayAdapter<DrillType> {
	private ArrayList<DrillType> items;
	/**
	 * @param context
	 * @param textViewResourceId
	 * @param objects
	 */
	public SelectTypesAdapter(Context context, int textViewResourceId,
			ArrayList<DrillType> objects) {
		super(context, textViewResourceId, objects);
		this.items = objects;			
	}
	
	 @Override
     public View getView(int position, View convertView, ViewGroup parent) {
         View view = convertView;
         if (view == null) {
             LayoutInflater layoutInflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        	 view = layoutInflater.inflate(R.layout.drill_type_edit_element, null);
         }
         DrillType drillType = items.get(position);
         if (drillType != null) {
             TextView rowTextView = (TextView) view;             
             if (rowTextView != null) {            	 
            	 rowTextView.setText(drillType.getName());                            
             }
         }
         return view;
     }	 
	 
	 @Override
	 public View getDropDownView(int position, View convertView, ViewGroup parent) {
		 View view = convertView;
         if (view == null) {
             LayoutInflater layoutInflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        	 view = layoutInflater.inflate(R.layout.drill_type_edit_element, null);
         }
         DrillType drillType = items.get(position);
         if (drillType != null) {
             TextView itemTextView = (TextView) view;             
             if (itemTextView != null) {            	 
            	 itemTextView.setText(drillType.getName());
            	 //itemTextView.setBackgroundColor(drillType.getColor());
             }
         }
         return view;
	 }
}
